package FourArithmeticOperations;

/**
 * Created by dell on 2017/10/18.
 */
    public class LinkedQueue<T>
        {
        private int count;
        private LinearNode<T> front, rear;
        public LinkedQueue()
        {
            count = 0;
            front = rear = null;
        }
        public void enqueue (T element)
        {
            LinearNode<T> node = new LinearNode<T>(element);

            if (isEmpty())
                front = node;
            else
                rear.setNext (node);

            rear = node;
            count++;
        }
        public T dequeue() {

            T result = front.getElement();
            front = front.getNext();
            count--;

            return result;
        }
        public T first()
        {
            return front.getElement();
        }
        public boolean isEmpty()
        {
            return (count==0);
        }
        public int size()
        {
            return count;
        }
        public String toString()
        {
            String result = "";
            LinearNode<T> current = front;

            while (current != null)
            {
                result = result + (current.getElement()).toString() + "\n";
                current = current.getNext();
            }

            return result;
        }
    }
